const fs = require('fs');
const path = require('path');

function fileSize(currentDirPath, callback) {
   let filesize = 0
    fs.readdir(currentDirPath, function (err, files) {
        if (err) {
            throw new Error(err);
        }
        files.forEach(function (name) {
            var filePath = path.join(currentDirPath, name);
            var stat = fs.statSync(filePath);
            if (stat.isFile()) {
              filesize += stat.size
            } else if (stat.isDirectory()) {
                fileSize(filePath, callback);
            }
        });
        callback(filesize);
    });
}

fileSize(__dirname, function(size) {
  console.log('文件大小为:' + size)
});

